QuickOPC User's Guide and Reference
Installed Examples - Web - UADataGridWebApplication

Demonstrates how easily can WebControls.GridView be populated with data read from OPC UA server.

The default page code-behind:

// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.

// UADataGridWebApplication: Demonstrates how easily can GridView be populated with data read from OPC UA server.

// ReSharper disable ArrangeModifiersOrder
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedAutoPropertyAccessor.Local

using System;
using System.Collections.Generic;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.UA;

namespace UADataGridWebApplication
{
    public partial class _Default : System.Web.UI.Page
    {
        class Row
        {
            public string NodeId { get; set; }
            public string Value { get; set; }
        }

        // Use a shared client instance to allow for better optimization.
        static private readonly EasyUAClient Client = new EasyUAClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            var nodeDescriptors = new UANodeDescriptor[]
                {
                    "nsu=http://test.org/UA/Data/ ;i=10844",
                    "nsu=http://test.org/UA/Data/ ;i=10853",
                    "nsu=http://test.org/UA/Data/ ;i=11017",
                    "nsu=http://test.org/UA/Data/ ;i=10845"
                };

            ValueResult[] valueResults = Client.ReadMultipleValues(
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
                nodeDescriptors);

            var data = new List<Row>();
            for (int i = 0; i < nodeDescriptors.Length; i++)
                data.Add(new Row
                    {
                        NodeId = nodeDescriptors[i].NodeId, 
                        Value = valueResults[i].Value?.ToString()
                    });

            GridView1.DataSource = data;
            GridView1.DataBind();
        }
    }
}

 

See Also